package com.example.d6_homework.homework07.service.impl;

import com.example.d6_homework.homework07.exception.DrawMoneyException;
import com.example.d6_homework.homework07.service.AtmService;

/**
 * ATM机业务处理类
 */
public class AtmServiceImpl implements AtmService {

    // 定义总金额
    private double totalMoney = 20000;

    // 取钱的方法
    @Override
    public double drawMoney(double money) {
        // 如果取钱大于总金额,或者 取钱小于0,就抛出异常
        if (money > totalMoney || money < 0) {
            throw new DrawMoneyException("取钱失败,余额不足");
        } else {
            return totalMoney - money;
        }
    }
}
